package JavaSE.d5;

import java.util.*;

//	找出字符串中出现次数最多的字符和出现的次数，输出到控制台
public class Test19 {
    public static void main(String[] args){
        String s="www.javakc.com/login.jsp";
        getStr(s);
    }
    public static void getStr(String s){
        char[] chars = s.toCharArray();
        Map<Object,Integer> m= new HashMap<>();


        for (char aChar : chars) {
            if(m.get(aChar)!=null){
                m.put(aChar,m.get(aChar)+1);
            }else {
                m.put(aChar,m.getOrDefault(aChar,1));//getOrDefault(键,默认值)如果能找到键则返回值，否则返回默认值
            }
        }
        System.out.println(m);
        System.out.print("出现最多字符: ");
        Integer max = Collections.max(m.values());
        for (Object o : m.keySet()) {
            if(m.get(o).equals(max)){
                System.out.print(o+" ");
            }
        }

    }
}
